<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <script>

    //复合数据(开发常用的数据格式)
    var data = {
      id: 'A0001',
      book: {
        name: 'JS',
        price: 58.88,
        author: ['kevin', '小明']
      },

      city: {
        name: '广州',
        area: [
          {
            name: '天河区',
            code: 'T001'
          },
          {
            name: '从化区',
            code: 'C001'
          }
        ]
      }
    };

    //获取data的book的name
    var bookName = data.book.name;
    console.log('bookName ==> ', bookName);

    //查看data的book的author每个作者
    var author = data.book.author;
    console.log('author ==> ', author);
    author.forEach(function (value) {
      console.log('value ==> ', value);
    })

    //获取广州所有的区
    var area = data.city.area;
    area.forEach(function (item) {
      console.log('item ==> ', item);
      var areaName = item.name;
      console.log('areaName ==> ', areaName);
    })


    //练习: 计算购物车的订单总价
    //isBuy: 表示用户勾选
    var shopcart = [
      {
        pname: '黑布林',
        price: 10,
        count: 2,
        isBuy: true
      },
      {
        pname: '刺客',
        price: 18,
        count: 4,
        isBuy: true
      },
      {
        pname: '大白兔糖果',
        price: 20,
        count: 3,
        isBuy: false
      },
      {
        pname: 'iphone14promax',
        price: 1,
        count: 1,
        isBuy: false
      },
      {
        pname: '卫龙辣条',
        price: 5,
        count: 5,
        isBuy: true
      }
    ];
   
  </script>
</body>

<